<script>
	import {
		getStorage,
		removeStorage
	} from '@/util/auth.js';
	import {
		isLogin
	} from '@/util/user.js'
	export default {
		onLaunch: function() {},
		onLaunch() {
			uni.loadFontFace({
				source: 'url("https://guoyuan-1306862033.cos.ap-chengdu.myqcloud.com/%E6%96%B9%E6%AD%A3%E6%B1%89%E7%9C%9F%E5%B9%BF%E6%A0%87%E7%AE%80%E4%BD%93.TTF")',
				family: 'FangZhengHanZhenGuangBiaoJianTi',
				global: true,
				success(e) {
					console.log(e)
				},
				fail(e) {
					console.log(e)
				}
			})
			let _this = this;
			uni.addInterceptor('navigateTo', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('redirectTo', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('reLaunch', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('switchTab', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
		},
		methods: {
			watchRouter(e) {
				let url = e.url;
				const index = url.indexOf('?');
				url = index == -1 ? url : url.slice(0, index);
				const hasToken = getStorage('login');
				const whiteList = ['/pages/home/home', '/pages/mine/index', '/pages/lighthouse/index',
					'/pages/project/project', '/pages/financial/financial', '/pages/work/work', '/pages/work/detail',
					'/pages/business/business ', '/pages/policy/detail', '/pages/supervise/supervise',
					'/pages/supervise/detail', '/pages/supervise/secretary', '/pages/supervise/secretary_detail',
					'/pages/supervise/superintendent-secretary', '/pages/supervise/supervise-detail',
					'/pages/supervise/secretary-list', '/pages/leader/leader', '/pages/search-list/search-list',
					'/pages/search-list/project-detail', '/pages/search-list/fund-detail',
					'/pages/search-list/work-detail', '/pages/search-list/business-detail',
					'/pages/search-list/superviso-detail', '/pages/rural-revitalization/index',
					'/pages/rural-revitalization/webview'
				];
				if (hasToken) {
					if (hasToken.userName != '游客' || whiteList.includes(url) || url ==
						'/pages/mine/profile') {
						return true;
					} else {
						uni.showModal({
							title: '提示',
							content: '需要先完善信息！',
							cancelText: '先逛逛',
							confirmText: '去完善',
							success(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/mine/profile'
									})
								} else {
									uni.navigateBack();
								}
							}
						})
					}
				} else {
					if (whiteList.includes(url)) {
						return true
					} else {
						uni.showModal({
							title: '提示',
							content: '需要先登录！',
							cancelText: '先逛逛',
							confirmText: '去登录',
							success(res) {
								if (res.confirm) {
									uni.switchTab({
										url: '/pages/mine/index'
									})
								} else {
									uni.navigateBack();
								}
							}
						})
					}
				}
				return false;
			}
		}
	}
</script>

<style lang="scss">
	@import url("@/static/iconfont/iconfont.css");

	view,
	text,
	navigator,
	input,
	picker,
	button,
	image {
		box-sizing: border-box;
	}

	.FangZhengHanZhenGuangBiaoJianTi {
		font-family: 'FangZhengHanZhenGuangBiaoJianTi';
	}

	.empty {
		text-align: center;
		color: #313131;
		font-size: 28rpx;
		margin: 30rpx 0;
	}

	page {
		min-height: calc(100vh - var(--window-bottom) - var(--window-top));
	}

	.inputPlaceholder {
		color: #999;
		font-weight: normal;
	}

	.require {
		color: red;
	}

	.btn {
		height: 90rpx;
		font-size: 30rpx;
		border-radius: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.btn.normal {
		background: $uni-color-primary;
		color: #fff;
	}

	.btn.normal-hollow {
		color: $uni-color-primary;
		border: 1px solid $uni-color-primary;
	}
</style>